import sun.font.FontRunIterator;

public class ShuzuFangfa {
    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[0]);
        System.out.println(array[1]);
        System.out.println(array[2]);
        System.out.println(array[3]);
        /*System.out.println(array[4]);*/ //err
        System.out.println(array.length);//数组变量. 调用方法得数组长度
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();

        //foreach循环、增强for循环
        for (int x:array//与下标无关全遍历的
             ) {
            System.out.print(x + " ");

        }
    }
    public static void main5(String[] args) {
        char[] array = new char[10];
        double[] array2 = new double[10];
        boolean[] array3 = new boolean[10];
        String[] strings = new String[10];
    }
    public static void main4(String[] args) {
        int[] array1 = {1,2,3,4};
        int[] array2 = new int[10];//赋上一个大小为10全为0的数组
        int[] array3 = new int[]{1,2,3,4,5,6,7};//有值的赋
        System.out.println(array1);//哈希值
        System.out.println(array2);
        System.out.println(array3);

        int[] array4;
        array4 = new int[10];

        int[] array5;
        array5 = new int[]{1,2,3,4,5};

        int[] array6;
        /*array6 = {1,2,3,4,5,6,7,8,9,10};*/ //err
    }

    public static int add(int x, int y){
        return x + y;
    }
    public static int add(double x,int y){
        return (int)(x+y);
    }

    public static void main3(String[] args) {//方法重载
        int ret = add(1,2);
        int ret2 = add(1.0,2);
    }
    public static void printf(int n){//打印123每一位
        if(n < 10){
            System.out.println(n);
            return;
        }
        printf(n/10);
        System.out.println(n%10);
    }
    public static int sumN(int n){//1到n的和
        if(n == 1){
            return 1;
        }
        return n + sumN(n-1);
    }
    public static int func(int n){//每一位数字的和
        if(n < 10) {
            return n;
        }
        return func(n/10) +n%10;
    }
    public static int fib2(int n){//斐波那契循环
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = -1;
        for (int i = 2; i <n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static int fib(int n){//斐波那契递归
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }
    public static int fact(int n){//n!
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }
    public static int facSum(int n){//1到n的阶乘和
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum+=fact(i);
        }
        return sum;
    }
    public static void main2(String[] args) {
        int n = 5;
        System.out.println(facSum(n));
        System.out.println(fact(5));
        System.out.println(fact(4));
        System.out.println(fact(3));
        System.out.println(fact(2));
        System.out.println(fact(1));

    }
    public  static boolean isLeapYear(int year){//判断闰年
        if(0 == year % 4 && 0!= year%100 || year % 400 == 0){
            return true;
        }
        return false;//不满足这个条件的话也要有返回
    }
    public static void main1(String[] args) {
        boolean flg = isLeapYear(2014);
        System.out.println(flg);
        boolean flg2 = isLeapYear(1987);
        System.out.println(flg2);
    }
}
